#include "perspective.h"

// PerspectiveCamera Method Definitions
PerspectiveCamera:: PerspectiveCamera(const Transform &cam2world,
        const float screenWindow[4], float sopen, float sclose,
        float lensr, float focald, float fov, Film *f)
    : ProjectiveCamera(cam2world, Perspective(fov, 1e-2f, 1000.f),
                       screenWindow, sopen, sclose, lensr, focald, f) {
    // Compute differential changes in origin for perspective camera rays
    dxCamera = RasterToCamera(Point(1,0,0)) - RasterToCamera(Point(0,0,0));
    dyCamera = RasterToCamera(Point(0,1,0)) - RasterToCamera(Point(0,0,0));
}


float PerspectiveCamera::GenerateRay(const CameraSample &sample,
                                     Ray *ray) const {
    // Generate raster and camera samples
    Point Pras(sample.imageX, sample.imageY, 0);
    Point Pcamera;
    RasterToCamera(Pras, &Pcamera);
    *ray = Ray(Point(0,0,0), Normalize(Vector(Pcamera)), 0.f, INFINITY);
    // Modify ray for depth of field
//    if (lensRadius > 0.) {
//        // Sample point on lens
//        float lensU, lensV;
//        ConcentricSampleDisk(sample.lensU, sample.lensV, &lensU, &lensV);
//        lensU *= lensRadius;
//        lensV *= lensRadius;

//        // Compute point on plane of focus
//        float ft = focalDistance / ray->d.z;
//        Point Pfocus = (*ray)(ft);

//        // Update ray for effect of lens
//        ray->o = Point(lensU, lensV, 0.f);
//        ray->d = Normalize(Pfocus - ray->o);
//    }
    ray->time = Lerp(sample.time, shutterOpen, shutterClose);
    CameraToWorld(*ray, ray);
    return 1.f;
}


